﻿using System;
using System.Collections.Generic;
using System.Text;
using ThomasGIS.Coordinates;
using ThomasGIS.Geometries;

namespace ThomasGIS.Grids.Basic
{
    public class Raster : IRaster
    {
        public int Rows { get; }
        public int Cols { get; }

        private RasterDataType rasterDataType;

        private Point LeftTopPoint = new Point(0, 0);

        private double xScale = 1;

        private double yScale = 1;

        public double RasterXMin => LeftTopPoint.X;

        public double RasterYMax => LeftTopPoint.Y;

        public double XScale => xScale;

        public double YScale => yScale;

        // 设置地理变换参数
        public bool SetGeoTransform(double xMin, double yMax, double xScale, double yScale)
        {
            this.LeftTopPoint.X = xMin;
            this.LeftTopPoint.Y = yMax;
            this.xScale = xScale;
            this.yScale = yScale;
            return true;
        }

        public int RasterBandNumber => bandList.Count;

        private List<RasterBand> bandList;

        private CoordinateBase rasterCoordinate;

        public CoordinateBase GetCoordinateSystem()
        {
            return rasterCoordinate;
        }

        public bool SetCoordinateSystem(CoordinateBase coordinateSystem)
        {
            this.rasterCoordinate = coordinateSystem;
            return true;
        }

        public Raster(int rows, int cols, RasterDataType type, CoordinateBase coordinateBase = null)
        {
            this.Rows = rows;
            this.Cols = cols;
            this.rasterDataType = type;
            this.bandList = new List<RasterBand>();
            this.rasterCoordinate = coordinateBase;
        }

        public bool AddRasterBand(RasterBand rasterBand)
        {
            if (rasterBand.Rows == this.Rows && rasterBand.Cols == this.Cols)
            {
                bandList.Add(rasterBand);
                return true;
            }

            return false;
        }

        public bool RemoveRasterBand(int index)
        {
            if (index >= RasterBandNumber || index < 0)
            {
                return false;
            }

            bandList.RemoveAt(index);
            return true;
        }

        public RasterBand GetRasterBand(int index)
        {
            if (index >= RasterBandNumber || index < 0)
            {
                return null;
            }

            return bandList[index];
        }

        public bool ExportToGTiff(string filepath)
        {
            return true;
        }

        public bool ExportToENVIStandard(string filepath, ENVIEncodingType type)
        {
            return true;
        }
    }
}
